<?xml version="1.0" encoding="UTF-8" ?>
<!--
 *************************************************************************
 * The contents of this file are subject to the Openbravo  Public  License
 * Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
 * Version 1.1  with a permitted attribution clause; you may not  use this
 * file except in compliance with the License. You  may  obtain  a copy of
 * the License at http://www.openbravo.com/legal/license.html
 * Software distributed under the License  is  distributed  on  an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific  language  governing  rights  and  limitations
 * under the License.
 * The Original Code is Openbravo ERP.
 * The Initial Developer of the Original Code is Openbravo SLU
 * All portions are Copyright (C) 2010-2012 Openbravo SLU
 * All Rights Reserved.
 * Contributor(s):  ______________________________________.
 *************************************************************************
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title id="paramTitle">xxTitle</title>
<link rel="shortcut icon" href="../../../../../web/images/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="../../../../../web/skins/Default/Openbravo_ERP_250.css" id="paramCSS"></link>

<script language="JavaScript" type="text/javascript" id="paramDirectory">
  var baseDirectory = "../../../../../web/";
</script>
<script language="JavaScript" src="../../../../../web/js/messages.js" type="text/javascript"></script>
<script language="JavaScript" src="../utility/DynamicJS.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript" id="paramLanguage">
  var defaultLang = "en_US";
</script>
<script language="JavaScript" src="../../../../../web/js/shortcuts.js" type="text/javascript"></script>
<script language="JavaScript" src="../../../../../web/js/utils.js" type="text/javascript"></script>
<script language="JavaScript" src="../../../../../web/js/windowKeyboard.js" type="text/javascript"></script>
<script language="JavaScript" src="../../../../../web/js/appStatus.js" type="text/javascript"></script>
<script language="JavaScript" src="../../../../../web/js/searchs.js" type="text/javascript"></script>
<script language="JavaScript" src="../../../../../web/js/ajax.js" type="text/javascript"></script>
<script language="JavaScript" src="../../../../../web/js/default/MessageBox.js" type="text/javascript"></script>
<script language="JavaScript" src="../../../../../web/js/messages.js" type="text/javascript"></script>
<script language="JavaScript" src="../utility/DynamicJS.js" type="text/javascript"></script>
<script language="JavaScript" src="../../../../../web/org.openbravo.userinterface.selector/js/classic-skin-variable.js" type="text/javascript"></script>
<script language="JavaScript" src="../../../../../web/../org.openbravo.client.kernel/OBCLKER_Kernel/StaticResources" type="text/javascript"></script>
<script language="JavaScript" src="../../../../../web/js/calculator.js" type="text/javascript"></script>
<script language="JavaScript" src="../../../../../web/js/jscalendar/calendar.js" type="text/javascript"></script>
<script language="JavaScript" src="../../../../../web/js/jscalendar/lang/calendar-es.js" type="text/javascript" id="fieldCalendar"></script>
<script language="JavaScript" src="../../../../../web/js/default/DateTextBox.js" type="text/javascript"></script>
<script language="JavaScript" src="../../../../../web/org.openbravo.advpaymentmngt/FIN_Utilities.js" type="text/javascript"></script>
<script language="JavaScript" src="../../../../../web/js/appStatus.js" type="text/javascript"></script>
<script type="text/javascript">
  window.onunload = reloadOpener; // reloads opener on closing
</script>
<script language="JavaScript" type="text/javascript">
  OB.APRM = OB.APRM || {};
  OB.APRM.APFT_GLItems = [];
  OB.APRM.APFT_GLItemsId = 0;
  OB.APRM.HasGLItems = false;
  OB.APRM.AOOI_bp = null;
var hasBPartner = null;
</script>
<script language="JavaScript" type="text/javascript">
//Ajax calls
function distributeAmount(_amount) {
  var amount = applyFormat(_amount);
  var distributedAmount = 0;
  var keepSelection = false;
  var chk = frm.inpScheduledPaymentDetailId;
  var scheduledPaymentDetailId, outstandingAmount, j, i;
  if (isGLItemEnabled) {
    amount = subtract(amount, frm.inpGLSumAmount.value);
  }
  
  if (!chk) {
    updateTotal();
    return;
  } else if (!chk.length) {
    scheduledPaymentDetailId = frm.inpRecordId0.value;
    outstandingAmount = frm.elements["inpRecordAmt" + scheduledPaymentDetailId].value;
    if ( compare(outstandingAmount, '>', amount) ) {
      outstandingAmount = amount;
    }
    frm.elements["inpPaymentAmount" + scheduledPaymentDetailId].value = outstandingAmount;
    if (!chk.checked && compare(outstandingAmount, '!=', 0)) {
      chk.checked = true;
      updateData(chk.value, chk.checked);
    }
  } else {
    var total = chk.length;
    for ( i = 0; i < total; i++) {
      if (chk[i].checked) {
        distributedAmount = add(distributedAmount, frm.elements["inpPaymentAmount" + chk[i].value].value);
      }
    }
    if (compare(amount, '>', distributedAmount) || compare(amount, '==', distributedAmount)) {
      amount = subtract(amount, distributedAmount);
      keepSelection = true;
    }
    for (i = 0; i < total; i++) {
      scheduledPaymentDetailId = frm.elements["inpRecordId" + i].value;
      outstandingAmount = frm.elements["inpRecordAmt" + scheduledPaymentDetailId].value;
      if (chk[i].checked && keepSelection) {
        if(compare(outstandingAmount, '<', amount) && compare(distributedAmount, '==', outstandingAmount))
          continue;
        else
          amount = add(amount, frm.elements["inpPaymentAmount" + chk[i].value].value);
      }
      if ( compare(outstandingAmount, '>', amount) ) {
        outstandingAmount = amount;
      }
      if ( compare(amount, '==', 0) && compare(outstandingAmount, '>=', 0 )) {
        frm.elements["inpPaymentAmount" + scheduledPaymentDetailId].value = "";
        for ( j = 0; j < total; j++) {
          if (chk[j].checked && chk[j].value === scheduledPaymentDetailId) {
            chk[j].checked = false;
            updateData(chk[j].value, chk[j].checked);
          }
        }
      } else {
        frm.elements["inpPaymentAmount" + scheduledPaymentDetailId].value = outstandingAmount;
        for ( j = 0; j < total; j++) {
          if (!chk[j].checked && chk[j].value === scheduledPaymentDetailId) {
            chk[j].checked = true;
            updateData(chk[j].value, chk[j].checked,null ,true );
          }
        }
        amount = subtract(amount, outstandingAmount);
      }
    }
  }
  updateTotal();
  return true;
}

function bPartnerBlocked(){
  try {
    var url = "../org.openbravo.furniture.ad_actionButton/AddOrderOrInvoiceFurniture.html";
    var paramXMLReq = null;
    return submitXmlHttpRequest(callBackBPartnerBlocked, document.frmMain, "BPARTNERBLOCK", url, false, null, paramXMLReq);
  } catch (e) {
    alert(e);
  }
}

function callBackBPartnerBlocked(paramXMLParticular, XMLHttpRequestObj) {
  if (getReadyStateHandler(XMLHttpRequestObj)) {
    try {
      if (XMLHttpRequestObj.responseText) {
        strText = XMLHttpRequestObj.responseText;
        var objson = eval(strText);
        showJSMessage(objson.text);
        return false;
      } else {
        openProcessPayment();
        return true;
      }
    } catch (e) {}
  }
  return true;
}

function callBackGrid(paramXMLParticular, XMLHttpRequestObj) {
  var strText = '';
  if (getReadyStateHandler(XMLHttpRequestObj)) {
    try {
      if (XMLHttpRequestObj.responseText) {
        strText = XMLHttpRequestObj.responseText;
        var aux = strText.substring(29, strText.length-8);
        var tableBody = document.getElementById('sectionGrid');
        var browserName = getBrowserInfo('name');
        if (browserName.toUpperCase().indexOf('INTERNET EXPLORER') !== -1) {
          var temp = document.createElement('span');
          temp.id = 'temp';
          temp.style.display = 'none';
          var newRows = '<table><tbody id=\"sectionGrid\">'+ aux;
          temp.innerHTML = newRows;
          tableBody.parentNode.replaceChild(temp.firstChild.firstChild, tableBody);
          if (temp.parentNode) {
            temp.parentNode.removeChild(temp);
          }
        } else {
          tableBody.innerHTML = aux;
        }

        if (document.frmMain.isFirstLoad.value === 'true'){
          document.frmMain.isFirstLoad.value='false';
          if (isTrue('isReceipt')) {
            var amount = document.frmMain.inpActualPayment.value;
            if (document.frmMain.inpUseCredit.checked) {
              amount = add(amount, document.frmMain.inpCredit.value);
            }
            distributeAmount(amount);
          }
        }
        updateAll();
        updateTotal();
      } else {
        document.getElementById('sectionGrid').innerHTML = '';
      }
    } catch (e) {
    }
  }
  return true;
}
function loadGridList() {
  if (OB.APRM.AOOI_bp === null ||
      OB.APRM.AOOI_bp !== document.getElementById('C_BPartner_ID').value ||
      OB.APRM.AOOI_dt !== document.getElementById('paramDocumentType').value ||
      OB.APRM.AOOI_pm !== document.getElementById('paramAlternativePaymentMethod').checked ||
      OB.APRM.AOOI_ddf !== document.getElementById('paramExpectedDateFrom').value ||
      OB.APRM.AOOI_ddt !== document.getElementById('paramExpectedDateTo').value ||
      OB.APRM.AOOI_cu !== document.getElementById('paramCurrencyId').value)
  {
    OB.APRM.AOOI_bp = document.getElementById('C_BPartner_ID').value;
    OB.APRM.AOOI_dt = document.getElementById('paramDocumentType').value;
    OB.APRM.AOOI_pm = document.getElementById('paramAlternativePaymentMethod').checked;
    OB.APRM.AOOI_ddf = document.getElementById('paramExpectedDateFrom').value;
    OB.APRM.AOOI_ddt = document.getElementById('paramExpectedDateTo').value;
    OB.APRM.AOOI_cu = document.getElementById('paramCurrencyId').value;

    try {
      var url = '../org.openbravo.furniture.ad_actionButton/AddOrderOrInvoiceFurniture.html';
      var paramXMLReq = null;
      return submitXmlHttpRequest(callBackGrid, document.frmMain, 'GRIDLIST', url, false, null, paramXMLReq);
    } catch (e) {
      alert(e);
    }
  }
}
</script>
<script language="JavaScript" type="text/javascript">
function setTextContent(element, text) {
  while (element.firstChild!==null) {
    element.removeChild(element.firstChild); // remove all existing content
  }
  var newdiv = document.createElement("div");
  newdiv.innerHTML = text.substring(5, text.length-6);
  element.appendChild(newdiv);
}
function loadGLItemList() {
  var table = document.getElementById('sectionGLItemGrid'),
      glitemCount = OB.APRM.APFT_GLItems.length,
      glitemAmount = 0,
      glitemDescLength = 20, glitemDescCont = "...",
      cellCount, row, cellGLItemDesc, cellGLITemReceivedInAmt, cellGLITemPaidOutAmt, cellRemoveButton, i, textNode, glAcctDimsDesc, glAcctDimsDescnext, acctDim, cellGLItemDim, cellText;

  setTextContent(table,'');
  if (!OB.APRM.HasGLItems) {
      var glItems = eval(document.getElementById('paramGLItems').value);
      if (glItems && glItems.length>0){
          OB.APRM.APFT_GLItems = glItems;
          OB.APRM.HasGLItems = true;
          var amountSelected = 0;
          for (i=0;i<glItems.length;i++){
            if (isTrue('isReceipt')) {
              amountSelected = add(amountSelected,glItems[i].glitemReceivedInAmt);
              amountSelected = subtract(amountSelected,glItems[i].glitemPaidOutAmt);
            } else {
              amountSelected = subtract(amountSelected,glItems[i].glitemReceivedInAmt);
              amountSelected = add(amountSelected,glItems[i].glitemPaidOutAmt);
            }
          }
          document.getElementById('paramGLItems').value = '';
          glitemCount = OB.APRM.APFT_GLItems.length;
          OB.APRM.APFT_GLItemsId = glitemCount; 
          frm.inpGLSumAmount.value = amountSelected;
          document.getElementById('paramGLItemsAmt').innerHTML = document.frmMain.inpGLSumAmount.value;
          updateTotal();
      }
  }
  if (glitemCount === 0) {
    OB.APRM.HasGLItems = false;
    frm.inpGLSumAmount.value = '0';
    updateTotal();
    return;
  }
  OB.APRM.HasGLItems = true;
  for (i = 0; i < glitemCount; i++) {
    row = table.insertRow(table.rows.length);
    row.className = 'DataGrid_Body_Row DataGrid_Body_Row_'+i%2;
    cellCount = 0;
    
    cellGLItemDesc = row.insertCell(cellCount);
    cellGLItemDesc.rowSpan = "2";
    textNode = document.createTextNode(OB.APRM.APFT_GLItems[i].glitemDesc);
    cellGLItemDesc.appendChild(textNode);
    cellGLItemDesc.className = 'DataGrid_Body_Cell';
    cellCount++;
    
    // Accounting Dimensions
    glAcctDimsDesc = ["cBpartnerDimDesc", "cActivityDimDesc", "mProductDimDesc", "cCampaignDimDesc"];
    glAcctDimsDescnext = ["cProjectDimDesc", "cCostcenterDimDesc", "user1DimDesc", "user2DimDesc"];
    for (acctDim = 0; acctDim < glAcctDimsDesc.length; acctDim++) {
      if (OB.APRM.APFT_GLItems[i][glAcctDimsDesc[acctDim]]) {
        cellGLItemDim = row.insertCell(cellCount);
        if (OB.APRM.APFT_GLItems[i][glAcctDimsDesc[acctDim]].length > glitemDescLength + glitemDescCont.length) {
          textNode = document.createTextNode(OB.APRM.APFT_GLItems[i][glAcctDimsDesc[acctDim]].slice(0, glitemDescLength) + glitemDescCont);
        } else {
          textNode = document.createTextNode(OB.APRM.APFT_GLItems[i][glAcctDimsDesc[acctDim]]);
        }
        cellGLItemDim.appendChild(textNode);
        cellGLItemDim.className = 'DataGrid_Body_Cell';
        cellCount++;
      } else if (OB.APRM.APFT_GLItems[i][glAcctDimsDesc[acctDim].replace("Desc", "Displayed")]) {
        // The Acct. Dimen is displayed and the user has left it empty
        cellGLItemDim = row.insertCell(cellCount);
        textNode = document.createTextNode("");
        cellGLItemDim.appendChild(textNode);
        cellGLItemDim.className = 'DataGrid_Body_Cell';
        cellCount++;
      }
    }
    
    cellGLITemReceivedInAmt = row.insertCell(cellCount);
    textNode = document.createTextNode(applyFormatJSToOBMasked(OB.APRM.APFT_GLItems[i].glitemReceivedInAmt));
    cellGLITemReceivedInAmt.appendChild(textNode);
    cellGLITemReceivedInAmt.className = 'DataGrid_Body_Cell_Amount';
    cellGLITemReceivedInAmt.rowSpan = "2";
    cellCount++;
    
    cellGLITemPaidOutAmt = row.insertCell(cellCount);
    cellGLITemPaidOutAmt.rowSpan = "2";
    textNode = document.createTextNode(applyFormatJSToOBMasked(OB.APRM.APFT_GLItems[i].glitemPaidOutAmt));
    cellGLITemPaidOutAmt.appendChild(textNode);
    cellGLITemPaidOutAmt.className = 'DataGrid_Body_Cell_Amount';
    cellCount++;
    
    if (isTrue('isReceipt')) {
      glitemAmount = subtract(applyFormatJSToOBMasked(OB.APRM.APFT_GLItems[i].glitemReceivedInAmt), applyFormatJSToOBMasked(OB.APRM.APFT_GLItems[i].glitemPaidOutAmt));
    } else {
      glitemAmount = subtract(applyFormatJSToOBMasked(OB.APRM.APFT_GLItems[i].glitemPaidOutAmt), applyFormatJSToOBMasked(OB.APRM.APFT_GLItems[i].glitemReceivedInAmt));
    }
    cellRemoveButton = row.insertCell(cellCount);
    cellRemoveButton.rowSpan = "2";
    cellText = '<div><button type="button" id="buttonRemoveGLItem"'
        + ' class="ButtonLink_focus" onclick="removeGLItem(' + i + ', ' + applyFormatOBMaskedToJS(glitemAmount) + ');return false;"'
        + ' onfocus="buttonEvent(\'onfocus\', this); window.status=\'OK\'; return true;"'
        + ' onblur="buttonEvent(\'onblur\', this);"'
        + '  onkeyup="buttonEvent(\'onkeyup\', this);"'
        + '  onkeydown="buttonEvent(\'onkeydown\', this);"'
        + '  onkeypress="buttonEvent(\'onkeypress\', this);"'
        + '  onmouseup="buttonEvent(\'onmouseup\', this);"'
        + '  onmousedown="buttonEvent(\'onmousedown\', this);"'
        + '  onmouseover="buttonEvent(\'onmouseover\', this); window.status=\'OK\'; return true;"'
        + '  onmouseout="buttonEvent(\'onmouseout\', this);">'
        + '  <table class="Button"><tr><td>'
        + '    <img alt="Remove" title="Remove" src="../web/org.openbravo.advpaymentmngt/images/GLItemGridCancel-xButt.png" id="imgButtonRemove" border="0"/></td>'
        + '  </tr></table></button></div>';
    setTextContent(cellRemoveButton, cellText);

    row = table.insertRow(table.rows.length);
    row.className = 'DataGrid_Body_Row DataGrid_Body_Row_'+i%2;
    cellCount = 0;

    for (acctDim = 0; acctDim < glAcctDimsDescnext.length; acctDim++) {
        if (OB.APRM.APFT_GLItems[i][glAcctDimsDescnext[acctDim]]) {
            cellGLItemDim = row.insertCell(cellCount);
            if (OB.APRM.APFT_GLItems[i][glAcctDimsDescnext[acctDim]].length > glitemDescLength + glitemDescCont.length) {
              textNode = document.createTextNode(OB.APRM.APFT_GLItems[i][glAcctDimsDescnext[acctDim]].slice(0, glitemDescLength) + glitemDescCont);
            } else {
              textNode = document.createTextNode(OB.APRM.APFT_GLItems[i][glAcctDimsDescnext[acctDim]]);
            }
            cellGLItemDim.appendChild(textNode);
            cellGLItemDim.className = 'DataGrid_Body_Cell';
            cellCount++;
          } else if (OB.APRM.APFT_GLItems[i][glAcctDimsDescnext[acctDim].replace("Desc", "Displayed")]) {
            // The Acct. Dimen is displayed and the user has left it empty
            cellGLItemDim = row.insertCell(cellCount);
            textNode = document.createTextNode("");
            cellGLItemDim.appendChild(textNode);
            cellGLItemDim.className = 'DataGrid_Body_Cell';
            cellCount++;
          }
        }
  }
  updateTotal();
}
function addGLItem() {
  var amount = 0, glamount = 0, expectedAmt = 0;
  if (frm.inpGLItemReceivedInAmount.value === null || frm.inpGLItemReceivedInAmount.value === '') {
    setWindowElementFocus(frm.inpGLItemReceivedInAmount);
    showJSMessage(7);
    return false;
  } else if (frm.inpGLItemPaidOutAmount.value === null || frm.inpGLItemPaidOutAmount.value === '') {
    setWindowElementFocus(frm.inpGLItemPaidOutAmount);
    showJSMessage(7);
    return false;
  } else if (frm.inpcGlitemId.value === null || frm.inpcGlitemId.value === '') {
    setWindowElementFocus(frm.inpcGlitemId);
    showJSMessage(7);
    return false;
  } else if ( (compare(frm.inpGLItemReceivedInAmount.value, '==', 0) && compare(frm.inpGLItemPaidOutAmount.value, '==', 0)) ||
              (compare(frm.inpGLItemReceivedInAmount.value, '!=', 0) && compare(frm.inpGLItemPaidOutAmount.value, '!=', 0)) ) {
    setWindowElementFocus(frm.paramPaymentAmountGLItem);
    showJSMessage('APRM_JSAMOUNTDIFFTOZERO');
    return false;
  }
  if (isTrue('isReceipt')) {
    glamount = subtract(frm.inpGLItemReceivedInAmount.value, frm.inpGLItemPaidOutAmount.value);
  } else {
    glamount = subtract(frm.inpGLItemPaidOutAmount.value, frm.inpGLItemReceivedInAmount.value);
  }
  amount = add(document.frmMain.inpGLSumAmount.value, glamount);
  document.frmMain.inpGLSumAmount.value = amount;
  document.frmMain.inpExpectedPayment.value = add(document.frmMain.inpExpectedPayment.value, glamount);
  if (!isTrue('isReceipt')) {
    if (document.frmMain.inpUseCredit.checked) {
      amount = subtract(amount, document.frmMain.inpCredit.value);
      if ( compare(amount, '<', '0') ) {
        amount = 0;
      }
    }
    document.frmMain.inpActualPayment.value = amount;
  }

  OB.APRM.APFT_GLItemsId++;
  OB.APRM.APFT_GLItems.push({
    id: OB.APRM.APFT_GLItemsId,
    glitemId: frm.inpcGlitemId.value,
    glitemDesc: sc_C_Glitem_ID.selectorField.getDisplayValue(),
    cBpartnerDim: frm.inpCBPartnerId_dim && frm.inpCBPartnerId_dim.value,
    cBpartnerDimDesc: sc_C_BPartner_ID_dim.selectorField.getDisplayValue(),
    cBpartnerDimDisplayed: frm.strElement_BP.value,
    cActivityDim: frm.inpCActivityId && frm.inpCActivityId.value,
    cActivityDimDesc: sc_C_Activity_ID.selectorField.getDisplayValue(),
    cActivityDimDisplayed: frm.strElement_AY.value,
    mProductDim: frm.inpMProductId && frm.inpMProductId.value,
    mProductDimDesc:  sc_M_Product_ID.selectorField.getDisplayValue(),
    mProductDimDisplayed: frm.strElement_PR.value,
    cCampaignDim: frm.inpCampaignId && frm.inpCampaignId.value,
    cCampaignDimDesc: sc_C_Campaign_ID.selectorField.getDisplayValue(),
    cCampaignDimDisplayed: frm.strElement_MC.value,
    cProjectDim: frm.inpCProjectId && frm.inpCProjectId.value,
    cProjectDimDesc: sc_C_Project_ID.selectorField.getDisplayValue(),
    cProjectDimDisplayed: frm.strElement_PJ.value,
    cCostcenterDim: frm.inpCCostcenterId && frm.inpCCostcenterId.value,
    cCostcenterDimDesc: sc_C_Costcenter_ID.selectorField.getDisplayValue(),
    cCostcenterDimDisplayed: frm.strElement_CC.value,
    user1Dim: frm.inpUser1Id && frm.inpUser1Id.value,
    user1DimDesc: sc_User1_ID.selectorField.getDisplayValue(),
    user1DimDisplayed: frm.strElement_U1.value,
    user2Dim: frm.inpUser2Id && frm.inpUser2Id.value,
    user2DimDesc: sc_User2_ID.selectorField.getDisplayValue(),
    user2DimDisplayed: frm.strElement_U2.value,
    glitemReceivedInAmt: OB.Utilities.Number.OBMaskedToJS(frm.inpGLItemReceivedInAmount.value,
                                                          getGlobalDecSeparator(),
                                                          getGlobalGroupSeparator()),
    glitemPaidOutAmt: OB.Utilities.Number.OBMaskedToJS(frm.inpGLItemPaidOutAmount.value,
                                                       getGlobalDecSeparator(),
                                                       getGlobalGroupSeparator())
  });
  loadGLItemList();
}
function removeGLItem(key, removedAmount) {
  var removedAmount = applyFormatJSToOBMasked(removedAmount);
  if (!isTrue('isReceipt')){
    if ( compare(document.frmMain.inpActualPayment.value, '>', removedAmount) ) {
      document.frmMain.inpActualPayment.value = subtract(document.frmMain.inpActualPayment.value, removedAmount);
    } else {
      document.frmMain.inpActualPayment.value = 0;
    }
  }
  document.frmMain.inpGLSumAmount.value = subtract(document.frmMain.inpGLSumAmount.value, removedAmount);
  document.frmMain.inpExpectedPayment.value = subtract(document.frmMain.inpExpectedPayment.value, removedAmount);
  OB.APRM.APFT_GLItems.splice(key, 1);
  updateConvertedAmounts();
  loadGLItemList();
}
function displayMulticurrencyControls() {
  var invCurrency = document.getElementById('paramCurrencyId').value;
  var accountCurrency = document.getElementById('paramFinancialAccountCurrencyId').value;

  var display = ( invCurrency && accountCurrency && invCurrency != accountCurrency );

  displayLogicElement('multiCurrencyRow', display );
  if (document.frmMain.strNotAllowExchange.value === 'Y' && display) {  
      readOnlyLogicElement('paramExchangeRate', true);
      readOnlyLogicElement('paramActualConverted', true);
   }
  else {
      readOnlyLogicElement('paramExchangeRate', false);
      readOnlyLogicElement('paramActualConverted', false);
  }
}
</script>
<script language="JavaScript" type="text/javascript">
function validate(action) {
  var frm = document.frmMain;
  if (action === 'openprocess') {
    if (frm.inpActualPayment.value === null || frm.inpActualPayment.value === '') {
      setWindowElementFocus(frm.inpActualPayment);
      showJSMessage(7);
      return false;
    } else {
      var diffAction = frm.inpDifferenceAction,
          selectedAction = null, i, actionSelected = false;
      for (i = 0; i < diffAction.length; i++) {
        if (diffAction[i].checked) {
          actionSelected = true;
          break;
        }
      }
      if (actionSelected) {
         selectedAction = diffAction[i].value;
      }
      if (!validateSelectedPendingPayments(true, selectedAction)) { return false; }
    }
    OB.APRM.APFT_GLItems = OB.APRM.APFT_GLItems || [];
  }
  return true;
}

function updateAll(drivenByGrid) {
  var frm = document.frmMain;
  var chk = frm.inpScheduledPaymentDetailId;
  var recordAmount, i;

  frm.inpExpectedPayment.value = applyFormat('0');
  if (isGLItemEnabled) {
    frm.inpExpectedPayment.value = frm.inpGLSumAmount.value || applyFormat('0');
  }
  if (!chk) {
    return;
  } else if (!chk.length) {
    if (!chk.checked) {
      recordAmount = frm.elements["inpRecordAmt" + chk.value].value;
      frm.inpExpectedPayment.value = add(frm.inpExpectedPayment.value, recordAmount);
    }
    updateData(chk.value, chk.checked, drivenByGrid);
  } else {
    var total = chk.length;
    if (drivenByGrid){
      if(!document.getElementById('inpTotal') || document.getElementById('inpTotal').value !== applyFormat('0')){
        document.getElementById('inpTotal').value = applyFormat('0');
        for (i = 0; i < total; i++) {
          if(applyFormat(document.frmMain.elements['inpPaymentAmount'+chk[i].value].value) !== "" && chk[i].checked){
            document.getElementById('inpTotal').value = add(applyFormat(document.getElementById('inpTotal').value), applyFormat(document.frmMain.elements['inpPaymentAmount'+chk[i].value].value));
          }
        }
      }
    }
    for (i = 0; i < total; i++) {
      if (!chk[i].checked) {
        recordAmount = frm.elements["inpRecordAmt" + chk[i].value].value;
        frm.inpExpectedPayment.value = add(frm.inpExpectedPayment.value, recordAmount);
      }
      if (drivenByGrid){
        if (applyFormat(document.frmMain.elements['inpPaymentAmount'+chk[i].value].value) === "" || !chk[i].checked)
        {
          updateData(chk[i].value, chk[i].checked, drivenByGrid, true);
          if (chk[i].checked){
            document.getElementById('inpTotal').value = add(applyFormat(document.getElementById('inpTotal').value), applyFormat(document.frmMain.elements['inpPaymentAmount'+chk[i].value].value));
          }
        }
      }
      else{
          updateData(chk[i].value, chk[i].checked, drivenByGrid,true);
      }
    }
  }
  if (drivenByGrid){
    updateTotal();
  }
  return true;
}

function updateData(key, mark, drivenByGrid, all) {
  if (mark === null) { mark=false; }
  updateReadOnly(key, mark);
  var paymentAmount = document.frmMain.elements['inpPaymentAmount'+key];
  if (!isTrue('isReceipt')){
    if (mark && paymentAmount.value === '') {
      paymentAmount.value=document.frmMain.elements['inpRecordAmt'+key].value;
    }
  } else { // sales
    if (drivenByGrid && mark && !paymentAmount.value) {
      var total = document.getElementById('inpTotal').value ? document.getElementById('inpTotal').value : 0;
      var actualPayment = document.getElementById('paramActualPayment').value;
      if (frm.inpUseCredit.checked) {
        actualPayment = add(actualPayment, document.frmMain.inpCredit.value);
      }
      var gridAmt = document.frmMain.elements['inpRecordAmt'+key].value;
      if ( compare(actualPayment, '<', 0) && compare(gridAmt, '>=', 0) ) {
        paymentAmount.value = 0;
      } else {
        if ( compare(actualPayment, '<', 0) && compare(gridAmt, '<', 0) ) {
          total = abs(total);
          actualPayment = abs(actualPayment);
          subtotal = add(total, abs(gridAmt));
          if ( compare(subtotal, '>', actualPayment)) {
            paymentAmount.value = subtract(0, subtract(actualPayment, total));
          } else {
            paymentAmount.value = gridAmt;
          }
        } else {
          var subtotal = add(total, gridAmt);
          if ( compare(subtotal, '>', actualPayment)) {
            paymentAmount.value = subtract(actualPayment, total);
          } else {
            paymentAmount.value = gridAmt;
          }
        }
      }
    }
  }
  if (!all){
    updateTotal();
  }
      
  return true;
}
function validateDate(element){
  if(isValidDate(element.value, element.getAttribute('displayformat'))) {
    loadGridList();
  }
}
function paymentAmountOnChange(element){
  updateTotal();
  numberInputEvent('onchange', element);
}
function setGLItemMode(toGLItem){
  displayLogicElement('glitemRow', toGLItem);
  displayLogicElement('glitemAddRow', toGLItem);
  displayLogicElement('gridGLItem', toGLItem);
  displayLogicElement('totalInvoices', toGLItem);
  displayLogicElement('GLItemSelectorLbl', toGLItem);
  displayLogicElement('GLItemSelector', toGLItem);
  
  displayLogicElement('ExpectedDateFromLbl', !toGLItem);
  displayLogicElement('ExpectedDateFrom', !toGLItem);
  displayLogicElement('ExpectedDateToLbl', !toGLItem);
  displayLogicElement('ExpectedDateTo', !toGLItem);
  displayLogicElement('gridPayment', !toGLItem);
  displayLogicElement('totalGLItems', !toGLItem);
  displayLogicElement('inpAlternativeLabel', !toGLItem);
  displayLogicElement('inpAlternativeChkBox', !toGLItem);
  if (toGLItem) {
    displayLogicElement('bpartnerfilterRow', !toGLItem);
  } else {
    displayLogicElement('bpartnerfilterRow', !hasBPartner);
  }
  autoDisplayLogicDimensions(toGLItem);

  resizeAreaCreateFrom();
  if (toGLItem) {
    loadGLItemList();
  }
  return true;
}
function autoDisplayLogicDimensions(isDisplayed) {
  var displayLogicDimension = function (dimension, isDisplayed) {
    displayLogicElement(dimension + '_dim_label', isDisplayed);
    displayLogicElement(dimension + '_dim_inp', isDisplayed);
    displayLogicElement(dimension + '_th', isDisplayed)
  }
  var displayTitle = false;
  if (document.frmMain.strElement_BP.value === 'Y' && isDisplayed) {
    displayLogicDimension('c_bpartner_id', true);
    displayTitle = true;
  } else {
    displayLogicDimension('c_bpartner_id', false);
  }  
  if (document.frmMain.strElement_AY.value === 'Y' && isDisplayed) {
    displayLogicDimension('c_activity_id', true);
    displayTitle = true;
  } else {
    displayLogicDimension('c_activity_id', false);
  }
  
  if (document.frmMain.strElement_PR.value === 'Y' && isDisplayed) {
    displayLogicDimension('m_product_id', true);
    displayTitle = true;
  } else {
    displayLogicDimension('m_product_id', false);
  }
  if (document.frmMain.strElement_MC.value === 'Y' && isDisplayed) {
    displayLogicDimension('c_campaign_id', true);
    displayTitle = true;
  } else {
    displayLogicDimension('c_campaign_id', false);
  }
  
  if (document.frmMain.strElement_PJ.value === 'Y' && isDisplayed) {
    displayLogicDimension('c_project_id', true);
    displayTitle = true;
  } else {
    displayLogicDimension('c_project_id', false);
  }
  if (document.frmMain.strElement_CC.value === 'Y' && isDisplayed) {
    displayLogicDimension('c_costcenter_id', true);
    displayTitle = true;
  } else {
    displayLogicDimension('c_costcenter_id', false);
  }
  if (document.frmMain.strElement_U1.value === 'Y' && isDisplayed) {
    displayLogicDimension('user1_id', true);
    displayTitle = true;
  } else {
    displayLogicDimension('user1_id', false);
  }
  if (document.frmMain.strElement_U2.value === 'Y' && isDisplayed) {
    displayLogicDimension('user2_id', true);
    displayTitle = true;
  } else {
    displayLogicDimension('user2_id', false);
  }
  
  if (displayTitle) {
    displayLogicElement('acctDimensionsTitle', true);
  } else {
    displayLogicElement('acctDimensionsTitle', false);
  }
}

function documentTypeOnChange(value){
  if ('G' === value) {
    //if we are not already on GL Item mode.
    if (!isTrue('isInGLItemMode')) {
      document.frmMain.isInGLItemMode.value='Y';
      document.getElementById('paramInvoicesAmt').innerHTML = frm.inpInvoiceAmount.value;
      setGLItemMode(true);
    }
  } else {
    document.getElementById('paramGLItemsAmt').innerHTML = document.frmMain.inpGLSumAmount.value;
    if (isTrue('isInGLItemMode')) {
      document.frmMain.isInGLItemMode.value='N';
      setGLItemMode(false);
    }
    loadGridList();
  }
}
function actualPaymentOnChange(){
  if (isTrue('isReceipt')) {
    var amount = document.frmMain.inpActualPayment.value;
    if (document.frmMain.inpUseCredit.checked) {
      amount = add(amount, document.frmMain.inpCredit.value);
    }
    if (isTrue('isInGLItemMode')) {
      updateTotal();
    } else {
      distributeAmount(amount);
    }
  }
}
function useCreditOnChange(){
  actualPaymentOnChange();
  updateTotal();
}
</script>
<script language="JavaScript" type="text/javascript">
function onLoadDo() {
  var tableTopPopup = new windowTableId('client_top_popup', 'buttonOK'),
      tableTop = new windowTableId('client_top', 'buttonProcess'),
      tableMiddle = new  windowTableId('client_middle', 'buttonProcess'),
      tableBottom = new windowTableId('client_bottom', 'buttonProcess');
  this.windowTables = new Array(tableTopPopup, tableTop, tableMiddle, tableBottom);

  setWindowTableParentElement();
  enableShortcuts('popup');
  setBrowserAutoComplete(false);
  hasBPartner = document.frmMain.inpBusinessPartnerId.value !== null && document.frmMain.inpBusinessPartnerId.value !== '';

  initFIN_Utilities(document.frmMain, hasBPartner, null, true);
  try {
    onloadFunctions();
  } catch (e) {}
  setGLItemMode(isTrue('isInGLItemMode'));
  displayLogicElement('sectionDifference', false);
  displayLogicElement('sectionDifferenceBox', false);
  processLabels();
  displayLogicElement('paramCustBalance', isReceipt);
  displayLogicElement('NoPackageslinkCalc', isTrue('isReceipt'));
  displayLogicElement('paramCredit', compare(document.getElementById('paramCredit').value, '>', '0') );
  displayLogicElement('lblCredit', compare(document.getElementById('paramCredit').value, '>', '0'));
  displayLogicElement('paramUseCredit', compare(document.getElementById('paramCredit').value, '>', '0') && compare(document.frmMain.inpGeneratedCredit.value, '==', '0') );
  displayLogicElement('lblUseCredit', compare(document.getElementById('paramCredit').value, '>', '0') && compare(document.frmMain.inpGeneratedCredit.value, '==', '0') );
  displayMulticurrencyControls();
  if (isTrue('isReceipt')) {
    setWindowElementFocus(frm.inpActualPayment);
  } else {
    document.getElementById('paramActualPayment').readOnly = true;
    document.getElementById('paramActualPayment').className = 'readonly required dojoValidateValid TextBox_btn_OneCell_width number';
    setWindowElementFocus(frm.inpDocNumber);
    updateTotal();
  }

  //numberInputEvent('onchange', document.frmMain.inpGLItemAmount);
  loadGridList();
  loadGLItemList();
  resizeAreaCreateFrom();

  //avoid horizontal scrolling when business partner column is displayed in the grid
  if (!document.getElementById('paramBusinessPartner').value) {
    popupResizeTo(1050, 600);
  }
}
function onResizeDo(){
  resizeAreaCreateFrom(true);
}
function submitThisPage(strCommand) {
  if (validate(strCommand)) {
    document.frmMain.inpGLItems.value = isc.JSON.encode(OB.APRM.APFT_GLItems);
    setProcessingMode('popup', true);
    submitCommandForm(strCommand, false, null, null);
    return true;
  }
  return true;
}
function openProcessPayment() {
  if (validate('openprocess')) {
    var amount = document.frmMain.inpActualPayment.value;
    // if amount is 0 deposit or withdrawn is not allowed
    // skip action regarding document window
    if ( compare(amount, '==', 0) ) {
      submitThisPage('SAVEANDPROCESS');
      return true;
    }
    document.getElementById('client_top_popup').style.display = 'block';
    document.getElementById('client_top').style.display = 'none';
    document.getElementById('client_middle').style.display = 'none';
    document.getElementById('client_bottom').style.display = 'none';
  }
}
function closeProcessPayment() {
  document.getElementById('client_top_popup').style.display = 'none';
  document.getElementById('client_top').style.display = 'block';
  document.getElementById('client_middle').style.display = 'block';
  document.getElementById('client_bottom').style.display = 'block';
  setGLItemMode(isTrue('isInGLItemMode'));
}
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload="onLoadDo();" onresize="onResizeDo();">
<form name="frmMain" method="post" action="AddOrderOrInvoiceFurniture.html">
  <input type="hidden" name="Command" />
  <input type="hidden" name="IsPopUpCall" value="1" />
  <input type="hidden" name="inpadOrgId" value="" id="fieldOrg"/>
    <input type="hidden" name="inpcOrderId" value="" id="fieldOrder"/>
  <input type="hidden" name="inpfinPaymentId" value="" id="fieldPayment"/>
  <input type="hidden" name="inpadWindowId" value="" id="fieldWindowId"/>
  <input type="hidden" name="inpTabId" value="" id="fieldTabId"/>
  <input type="hidden" name="isReceipt" value="" id="fieldReceipt"/>
  <input type="hidden" name="inpissotrx" value="" id="fieldIsSoTrx"/>
  <input type="hidden" name="isFirstLoad" value="true"/>
  <input type="hidden" name="isInGLItemMode" value="N"/>
  <input type="hidden" name="inpGLItems" id="paramGLItems"  value=""/>
  <input type="hidden" name="inpDeleteGLItem" value=""/>
  <input type="hidden" id="paramGeneratedCredit" name="inpGeneratedCredit" value="0"/>
  <input type="hidden" name="strElement_BP" id="paramStrElement_BP" value=""/>
  <input type="hidden" name="strElement_PR" id="paramStrElement_PR" value=""/>
  <input type="hidden" name="strElement_PJ" id="paramStrElement_PJ" value=""/>
  <input type="hidden" name="strElement_AY" id="paramStrElement_AY" value=""/>
  <input type="hidden" name="strElement_CC" id="paramStrElement_CC" value=""/>
  <input type="hidden" name="strElement_MC" id="paramStrElement_MC" value=""/>
  <input type="hidden" name="strElement_U1" id="paramStrElement_U1" value=""/>
  <input type="hidden" name="strElement_U2" id="paramStrElement_U2" value=""/>
  <input type="hidden" name="strNotAllowExchange" id="paramStrNotAllowExchange" value=""/>
  <input type="hidden" name="strWriteOffLimit" id="paramStrWriteOffLimit" value=""/>
  <input type="hidden" name="strtypewriteoff" id="paramStrtypewriteoff" value=""/>
  <input type="hidden" name="strAmountwriteoff" id="paramStrAmountwriteoff" value=""/>
  
  <div class="Popup_ContentPane_CircleLogo">
    <div class="Popup_WindowLogo">
      <img class="Popup_WindowLogo_Icon Popup_WindowLogo_Icon_process" src="../../../../../web/images/blank.gif" border=0/></img>
    </div>
  </div>
  <table cellspacing="0" cellpadding="0" width="100%" id="table_header">
    <tr>
      <td>
        <table cellspacing="0" cellpadding="0" class="Popup_ContentPane_NavBar">
          <tr class="Popup_NavBar_bg"><td></td>
            <td class="Popup_NavBar_separator_cell"></td>
            <td class="Popup_NavBar_bg_logo_left"></td>
            <td class="Popup_NavBar_bg_logo" width="1" onclick="openNewBrowser('http://www.openbravo.com', 'Openbravo');return false;"><img src="../../../../../web/images/blank.gif" alt="Openbravo" title="Openbravo" border="0" id="openbravoLogo" class="Popup_NavBar_logo" /></td>
            <td class="Popup_NavBar_bg_logo_right"></td>
            <td class="Popup_NavBar_Popup_title_cell"><span name="lblR" id="lblRPopupTitle">Add Payment In</span><span name="lblP" id="lblPPopupTitle">Add Payment Out</span></td>
            <td class="Popup_NavBar_separator_cell"></td>
          </tr>
        </table>
      </td>
    </tr>

    <tr>
      <td>
        <table cellspacing="0" cellpadding="0" class="Popup_ContentPane_SeparatorBar">
          <tr>
            <td class="Popup_SeparatorBar_bg"></td>
          </tr>
        </table>
      </td>
    </tr>

  </table>
  <table cellspacing="0" cellpadding="0" width="100%">
    <tr>
      <td>
        <div class="Popup_ContentPane_Client" style="overflow: auto;" id="client_messagebox">

          <!-- MessageBox -->
          <table cellpadding="0" cellspacing="0" id="messageBoxID" class="MessageBoxyy">
            <tbody>
            <tr class="MessageBox_TopMargin">
              <td class="MessageBox_LeftMargin"></td>
              <td></td>
              <td class="MessageBox_RightMargin"></td>
            </tr>
            <tr>
              <td class="MessageBox_LeftMargin"></td>
              <td>

                <table cellpadding="0" cellspacing="0" class="MessageBox_Container">
                  <tbody>
                  <tr>
                    <td class="MessageBox_LeftTrans">
                      <table style="width: 100%; height: 100%" cellpadding="0" cellspacing="0">
                        <tbody>
                        <tr>
                          <td class="MessageBox_TopLeft"></td>
                        </tr>
                        <tr>
                          <td class="MessageBox_Left"></td>
                        </tr>
                        </tbody>
                      </table>
                    </td>
                    <td class="MessageBox_bg">

                      <table class="MessageBox_Top">
                      <tbody>
                        <tr>
                          <td>
                            <span>
                            <table cellpadding="0" cellspacing="0" class="MessageBox_Body_ContentCell">
                              <tbody>
                              <tr>
                                <td class="MessageBox_Icon_ContentCell">
                                  <div class="MessageBox_Icon"></div>
                                </td>
                                <td style="vertical-align: top;" id="messageBoxIDContent">
                                  <span>
                                    <div class="MessageBox_TextTitle" id="messageBoxIDTitle">
                                      xxInfo: AccessTableWithNoView
                                    </div>
                                    <div class="MessageBox_TextDescription" id="messageBoxIDMessage">
                                      xxThe current information is empty.
                                    </div>
                                    <div class="MessageBox_TextSeparator"></div>
                                  </span>
                                </td>
                              </tr>
                              </tbody>
                            </table>
                            </span>
                          </td>
                        </tr>
                        </tbody>
                      </table>

                    </td>
                    <td class="MessageBox_RightTrans">
                      <table style="width: 100%; height: 100%" cellpadding="0" cellspacing="0">
                        <tbody>
                        <tr>
                          <td class="MessageBox_TopRight"></td>
                        </tr>
                        <tr>
                          <td class="MessageBox_Right"></td>
                        </tr>
                        </tbody>
                      </table>
                    </td>
                  </tr>
                  <tr>
                    <td rowspan="2" class="MessageBox_BottomLeft">
                    </td>
                    <td class="MessageBox_BottomTrans MessageBox_bg">
                    </td>
                    <td rowspan="2" class="MessageBox_BottomRight">
                    </td>
                  </tr>
                  <tr>
                    <td class="MessageBox_Bottom">
                    </td>
                  </tr>
                  </tbody>
                </table>

              </td>
              <td class="MessageBox_RightMargin"></td>
            </tr>
            <tr class="MessageBox_BottomMargin">
              <td class="MessageBox_LeftMargin"></td>
              <td></td>
                <td class="MessageBox_RightMargin"></td>
              </tr>
            </tbody>
          </table>
        <!-- MessageBox END -->
        </div>
      </td>
    </tr>
  </table>

  <table cellspacing="0" cellpadding="0" width="100%">

    <tr>
      <td>
        <!-- Hidden Process Payment Div  -->
        <div class="Popup_ContentPane_Client" style="display: none;" id="client_top_popup">
          <table cellspacing="0" cellpadding="0" class="Popup_ContentPane_InfoBar">
           <tr>
             <td class="Popup_InfoBar_Icon_cell"><img src="../web/images/blank.gif" class="Popup_InfoBar_Icon_info" border="0"></td>
             <td class="Popup_InfoBar_text_table">
               <table>
                 <tr><td class="Popup_InfoBar_text" id="processHelp">Process Payment</td></tr>
                 </table>
              </td>
            </tr>
          </table>
          <table cellspacing="0" cellpadding="0" class="Popup_Client_TableSelector">
            <tr>
              <td class="TableEdition_OneCell_width"></td>
              <td class="TableEdition_OneCell_width"></td>
              <td class="TableEdition_OneCell_width"></td>
              <td class="TableEdition_OneCell_width"></td>
              <td class="TableEdition_OneCell_width"></td>
              <td class="TableEdition_OneCell_width"></td>
            </tr>
            <tr><td colspan="6" height="20"></td></tr>
            <tr>
              <td class="TitleCell"></td>
              <td class="TitleCell" colspan="2"><span class="LabelText">Action regarding document</span></td>
              <td class="Combo_ContentCell">
                <select name="inpActionDocument" id="paramActionDocument" class="ComboKey Combo_TwoCells_width" required="true">
                  <div id="reportActionDocument"></div>
                </select>
              </td>
              <td class="TitleCell"></td>
              <td class="TitleCell"></td>
            </tr>
            <tr><td colspan="6" height="20"></td></tr>
            <tr>
              <td></td>
              <td></td>
              <td class="Button_RightAlign_ContentCell">
                <div>
                  <button type="button"
                    id="buttonOK"
                    class="ButtonLink_focus"
                    onclick="submitThisPage('SAVE');return false;"
                    onfocus="buttonEvent('onfocus', this); window.status='OK'; return true;"
                    onblur="buttonEvent('onblur', this);"
                    onkeyup="buttonEvent('onkeyup', this);"
                    onkeydown="buttonEvent('onkeydown', this);"
                    onkeypress="buttonEvent('onkeypress', this);"
                    onmouseup="buttonEvent('onmouseup', this);"
                    onmousedown="buttonEvent('onmousedown', this);"
                    onmouseover="buttonEvent('onmouseover', this); window.status='OK'; return true;"
                    onmouseout="buttonEvent('onmouseout', this);">
                    <table class="Button">
                      <tr>
                        <td class="Button_left"><img class="Button_Icon Button_Icon_ok" alt="OK" title="OK" src="../web/images/blank.gif" id="imgButtonOK" border="0"></td>
                        <td class="Button_text Button_width" id="tdButtonOK">OK</td>
                        <td class="Button_right"></td>
                      </tr>
                    </table>
                  </button>
                </div>
              </td>
              <td class="Button_LeftAlign_ContentCell">
                <div>
                  <button type="button"
                    id="buttonCancel"
                    class="ButtonLink"
                    onclick="closeProcessPayment();return false;"
                    onfocus="buttonEvent('onfocus', this); window.status='Cancel'; return true;"
                    onblur="buttonEvent('onblur', this);"
                    onkeyup="buttonEvent('onkeyup', this);"
                    onkeydown="buttonEvent('onkeydown', this);"
                    onkeypress="buttonEvent('onkeypress', this);"
                    onmouseup="buttonEvent('onmouseup', this);"
                    onmousedown="buttonEvent('onmousedown', this);"
                    onmouseover="buttonEvent('onmouseover', this); window.status='Cancel'; return true;"
                    onmouseout="buttonEvent('onmouseout', this);">
                    <table class="Button">
                      <tr>
                        <td class="Button_left"><img class="Button_Icon Button_Icon_cancel" alt="Cancel" title="Cancel" src="../web/images/blank.gif" id="imgButtonCancel" border="0"></td>
                        <td class="Button_text Button_width" id="tdButtonCancel">Cancel</td>
                        <td class="Button_right"></td>
                      </tr>
                    </table>
                  </button>
                </div>
              </td>
              <td></td>
              <td></td>
            </tr>
          </table>
        </div>
        <div class="Popup_ContentPane_Client" style="overflow: auto;" id="client_top">
          <table cellspacing="0" cellpadding="0" class="Popup_Client_TableSelector">

            <tr>
              <td class="TableEdition_OneCell_width"></td>
              <td class="TableEdition_OneCell_width"></td>
              <td class="TableEdition_OneCell_width"></td>
              <td class="TableEdition_OneCell_width"></td>
              <td class="TableEdition_OneCell_width"></td>
              <td class="TableEdition_OneCell_width"></td>
            </tr>

            <!-- Text -->
            <tr>
                <td colspan="6" class="LabelText" style="font-weight: bold;">
                    <span name="lblR" id="lblRText">Select sales orders, invoices or GL Items that you want to match to this payment in</span>
                    <span name="lblP" id="lblPText">Select purchase orders, invoices or GL Items that you want to match to this payment out</span>
                </td>
            </tr>
            
            <!-- Line 1 -->
            <tr>
              <td class="TitleCell"><span name="lblP" id="lblPPayingTo" class="LabelText">To Be Paid To</span><span name="lblR" id="lblRReceivingFrom" class="LabelText">Received From</span></td>
              <td class="TextBox_ContentCell" colspan="2"><input class="readonly dojoValidateValid TextBox_TwoCells_width" type="text" name="inpBusinessPartner" value="" id="paramBusinessPartner"></input>
              <input type="hidden" name="inpBusinessPartnerId" value="" id="paramBusinessPartnerId"></input></td>
              <td class="TitleCell"><span class="LabelText" name="lblR" id="lblRCustomerBalance">Customer Balance</span></td>
              <td class="TextBox_ContentCell"><input class="readonly dojoValidateValid TextBox_OneCell_width number" type="text" name="inpCustBalance" value="" id="paramCustBalance"></input></td>
              <td class="TitleCell"></td>
            </tr>

            <!-- Line hidden -->
            <tr style="display:none;">
              <td class="TitleCell"><span name="lblP" id="lblPExpectedPaym" class="LabelText">Expected Payment Out</span><span name="lblR" id="lblRExpectedPaym" class="LabelText">Expected Payment In</span></td>
              <td class="TextBox_ContentCell"> <input class="readonly dojoValidateValid required TextBox_OneCell_width number" type="text" id="paramExpectedPayment" name="inpExpectedPayment" value="" onchange="updateDifference();"></input>
              </td>
              <td class="TitleCell"></td>
              <td class="TitleCell"><span class="LabelText">Expected Converted</span></td>
              <td class="TextBox_ContentCell"> <input class="readonly dojoValidateValid required TextBox_OneCell_width number" type="text" id="paramExpectedConverted" name="inpExpectedConverted" value="" onchange="" disabled="true"></input>
              </td>
              <td class="TitleCell"></td>
            </tr>

            <!-- Line 2 -->
            <tr>
              <td class="TitleCell"><span name="lblP" id="lblPActualPaymentOut" class="LabelText">Actual Payment Out</span><span name="lblR" id="lblRActualPaymentIn" class="LabelText">Actual Payment In</span></td>
              <td class="TextBox_btn_ContentCell">
                  <table border="0" cellspacing="0" cellpadding="0" summary=""  style="padding-top: 0px;">
                    <tr>
                      <td class="Textbox_ContentCell">
                        <table style="border: 0px none; border-collapse: collapse;">
                        <tr><td style="padding-top: 0px;">
                          <input type="text" onblur="numberInputEvent('onblur', this);" onfocus="numberInputEvent('onfocus', this);" outputformat="euroEdition" onchange="actualPaymentOnChange();return true;" onpaste="changeToEditingMode('onpaste');" oncut="changeToEditingMode('oncut');" onkeypress="changeToEditingMode('onkeypress');" onkeydown="changeToEditingMode('onkeydown'); numberInputEvent('onkeydown', this, event);" onkeyup="" name="inpActualPayment" maxlength="22" value="" required="true" class="dojoValidateValid required TextBox_btn_OneCell_width number" id="paramActualPayment"/>
                          </td></tr>
                        </table>
                        <span id="paramActualPaymentinvalidSpan" style="display: none;" class="TextBox_MsgContainer_span">
                          <table class="TextBox_MsgContainer_table">
                            <tbody><tr class="TextBox_MsgContainer_tr">
                              <td class="TextBox_MsgContainer_td"><div class="TextBox_MsgContainer_div"></div></td><td></td>
                            </tr>
                            <tr>
                              <td class="invalid" colspan="2"><div name="invalidText" id="paramActualPaymentinvalidSpanText" class="TextBox_MsgContainer_div2">* The value entered is not valid.</div></td>
                            </tr>
                          </tbody></table>
                        </span>
                      </td>
                      <td class="FieldButton_ContentCell">
                      <a class="FieldButtonLink" href="#" onfocus="setWindowElementFocus(this); window.status='Amount From'; return true;" onblur=" window.status=''; return true;" onkeypress="this.className='FieldButtonLink_active'; return true;" onkeyup="this.className='FieldButtonLink_focus'; return true;"  onclick="calculator('frmMain.inpActualPayment', document.frmMain.inpActualPayment.value, false);return false;">
                      <table class="FieldButton" onmouseout="this.className='FieldButton';window.status='';return true;" onmouseover="this.className='FieldButton_hover';window.status='';return true;" onmousedown="this.className='FieldButton_active';return true;" onmouseup="this.className='FieldButton';return true;" id="NoPackageslinkCalc">
                          <tr>
                            <td class="FieldButton_bg">
                              <img alt="Calculator" class="FieldButton_Icon FieldButton_Icon_Calc" title="Amount" src="../../../../../web/images/blank.gif" border="0" id="buttonCalc"></img>
                            </td>
                          </tr>
                        </table>
                      </a>
                      </td>
                    </tr>
                  </table>
              </td>
              <td class="TitleCell"><span class="LabelText" name="lbl" id="lblCredit">Available Credit</span></td>
              <td class="TextBox_ContentCell"><input class="readonly dojoValidateValid TextBox_OneCell_width number" type="text" name="inpCredit" value="0" id="paramCredit"></input></td>
              <td class="TitleCell"><span class="LabelText" name="lbl" id="lblUseCredit">Use Available Credit</span></td>
              <td class="Radio_Check_ContentCell"><span class="Checkbox_container_NOT_Focused"><input type="checkbox" name="inpUseCredit" value="Y" id="paramUseCredit" onclick="useCreditOnChange();"></input></span></td>
            </tr>

            <!-- Line 3 -->
            <tr id="multiCurrencyRow">
              <td class="TitleCell"><span class="LabelText" id="lblActualConverted">Actual Converted</span></td>
              <td class="TextBox_ContentCell"> <input class="dojoValidateValid required TextBox_OneCell_width number" type="text" id="paramActualConverted" name="inpActualConverted" value="" onchange="updateConvertedAmounts(true);" ></input>
              </td>
              <td class="TextBox_ContentCell">
                <input type="hidden" id="paramFinancialAccountCurrencyId" name="financialAccountCurrencyId" value=""/>
                <input type="hidden" id="paramFinancialAccountCurrencyPrecision" name="inpFinancialAccountCurrencyPrecision" value="2"/>
                <input class="readonly dojoValidateValid required TextBox_OneCell_width" type="text" id="paramFinancialAccountCurrencyName" name="paramFinancialAccountCurrencyName" value=""></input>
              </td>
              <td class="TitleCell"><span class="LabelText" id="lblExchangeRate">Exchange Rate</span></td>
              <td class="TextBox_ContentCell"> <input class="dojoValidateValid required TextBox_OneCell_width number" type="text" id="paramExchangeRate" name="inpExchangeRate" value="" onchange="updateConvertedAmounts();" ></input>
              </td>
              <td class="TextBox_ContentCell">
                <input type="hidden" id="paramCurrencyId" name="inpCurrencyId" value=""/>
                <input class="readonly dojoValidateValid required TextBox_OneCell_width" type="text" id="paramCurrencyName" name="paramCurrencyName" value=""></input>
              </td>
            </tr>


            <tr class="FieldGroup_BottomMargin"></tr>
            
            <!-- Table filters -->
            <tr>
              <td class="TitleCell"><span class="LabelText"></span></td>
              <td class="Combo_ContentCell">
                <select id="paramDocumentType" name="inpDocumentType" class="ComboKey Combo_OneCell_width" onchange="documentTypeOnChange(this.value);" style="visibility: hidden;">
                  <option value="O">Orders</option>
                  <option value="I" selected="selected">Invoices</option>
                  <option value="B">Orders and Invoices</option>
                  <option value="G">GL Items</option>
                </select>
              </td>
              <td class="TitleCell" id="ExpectedDateFromLbl" colspan="2"><span class="LabelText"></span></td>
              <td class="TextBox_btn_ContentCell" id="ExpectedDateFrom">
                <table border="0" cellspacing="0" cellpadding="0" summary=""  style="padding-top: 0px;">
                  <tr>
                    <td class="TextBox_ContentCell">
                      <table style="border: 0px none; border-collapse: collapse;">
                        <tr><td style="padding-top: 0px;">
                          <input type="hidden" 
                          id="paramExpectedDateFrom" 
                          class="dojoValidateValid TextBox_btn_OneCell_width" 
                          value="" 
                          maxlength="10" 
                          name="inpExpectedDateFrom" 
                          onkeyup="autoCompleteDate(this);" 
                          onkeydown="changeToEditingMode('onkeydown');" 
                          onkeypress="changeToEditingMode('onkeypress');" 
                          oncut="changeToEditingMode('oncut');" 
                          onpaste="changeToEditingMode('onpaste');" 
                          oncontextmenu="changeToEditingMode('oncontextmenu');" 
                          onblur="expandDateYear(this.id);" 
                          onchange="validateDateTextBox(this.id); validateDate(this); return true;" 
                          displayFormat="xx" 
                          saveFormat="xx"></input>
                        </td></tr>
                      </table>
                      <span id="paramExpectedDateFrominvalidSpan" style="display: none;" class="TextBox_MsgContainer_span">
                        <table class="TextBox_MsgContainer_table">
                          <tbody><tr class="TextBox_MsgContainer_tr"><td class="TextBox_MsgContainer_td"><div class="TextBox_MsgContainer_div"></div></td><td></td></tr>
                          <tr><td class="invalid" colspan="2"><div name="invalidText" id="paramExpectedDateFrominvalidSpanText" class="TextBox_MsgContainer_div2">* The value entered is not valid.</div></td></tr>
                        </tbody></table>
                      </span>
                    </td>
                    <td class="FieldButton_ContentCell">
                      <a class="FieldButtonLink" href="#" onfocus="setWindowElementFocus(this); window.status='Calendar'; return true;" onblur="window.status=''; return true;" onkeypress="this.className='FieldButtonLink_active'; return true;" onkeyup="this.className='FieldButtonLink_focus'; return true;" onclick="showCalendar('frmMain.inpExpectedDateFrom', document.frmMain.inpExepctedDateFrom.value, false);return false;">
                        <table class="FieldButton" onmouseout="this.className='FieldButton';window.status='';return true;" onmouseover="this.className='FieldButton_hover';window.status='Show calendar';return true;" onmousedown="this.className='FieldButton_active';return true;" onmouseup="this.className='FieldButton';return true;">
                          <tr>
                            <td class="FieldButton_bg">
                            </td>
                          </tr>
                        </table>
                      </a>
                    </td>
                  </tr>
                </table>
              </td>
              <td class="TitleCell" id="GLItemSelectorLbl"><span class="LabelText">GL Item</span></td>
              <td class="TextBox_ContentCell" colspan="2" id="GLItemSelector">
                <table style="border:0px;border-collapse:collapse;">
                  <tr>
                    <td style="padding-top: 0px;">
                      <script>var sc_C_Glitem_ID = null;</script>
                      <input type="hidden" name="inpcGlitemId" id="C_Glitem_ID" value="" onreset="sc_C_Glitem_ID.resetSelector();" onchange="openbravo.Utilities.updateSmartClientComponentValue(this, sc_C_Glitem_ID.selectorField);"></input>
                      <script id="selectorLink" src="../org.openbravo.client.kernel/OBUISEL_Selector/9FAD469CE4414A25974CF45C0AD22D35?columnName=C_Glitem_ID&disabled=false&CssSize=TwoCells&DisplayLength=45.0&required=true"></script>
                    </td>
                  </tr>
                </table>
              </td>
            </tr>
            <tr>
              <td class="TitleCell" id="inpAlternativeLabel"><span class="TitleCell LabelText"><label name="lblP" id="lblPShowPaym" for="paramAlternativePaymentMethod"></label></span><span class="TitleCell LabelText"><label name="lblR" id="lblRShowPaym" for="paramAlternativePaymentMethod"></label></span></td>
              <td class="Radio_Check_ContentCell" id="inpAlternativeChkBox">
              <span class="Radio_Check_ContentCell Checkbox_container_NOT_Focused"><input type="hidden" name="inpAlternativePaymentMethod" value="Y" id="paramAlternativePaymentMethod" onclick="loadGridList()"></input></span>
              </td>
              <td class="TitleCell"></td>
              <td class="TitleCell" id="ExpectedDateToLbl"><span class="LabelText"></span></td>
              <td class="TextBox_btn_ContentCell" id="ExpectedDateTo">
                <table border="0" cellspacing="0" cellpadding="0" summary=""  style="padding-top: 0px;">
                  <tr>
                    <td class="TextBox_ContentCell">
                      <table style="border: 0px none; border-collapse: collapse;">
                        <tr><td style="padding-top: 0px;">
                          <input type="hidden" id="paramExpectedDateTo" class="dojoValidateValid TextBox_btn_OneCell_width" value="" maxlength="10" name="inpExpectedDateTo" onkeyup="autoCompleteDate(this);" onkeydown="changeToEditingMode('onkeydown');" onkeypress="changeToEditingMode('onkeypress');" oncut="changeToEditingMode('oncut');" onpaste="changeToEditingMode('onpaste');" oncontextmenu="changeToEditingMode('oncontextmenu');" onblur="expandDateYear(this.id);" onchange="validateDateTextBox(this.id); validateDate(this);return true;" displayFormat="xx" saveFormat="xx"></input>
                          </td></tr>
                      </table>
                      <span id="paramExpectedDateToinvalidSpan" style="display: none;" class="TextBox_MsgContainer_span">
                        <table class="TextBox_MsgContainer_table">
                          <tbody><tr class="TextBox_MsgContainer_tr"><td class="TextBox_MsgContainer_td"><div class="TextBox_MsgContainer_div"></div></td><td></td></tr>
                          <tr><td class="invalid" colspan="2"><div name="invalidText" id="paramExpectedDateToinvalidSpanText" class="TextBox_MsgContainer_div2">* The value entered is not valid.</div></td></tr>
                        </tbody></table>
                      </span>
                    </td>
                    <td class="FieldButton_ContentCell">
                      <a class="FieldButtonLink" href="#" onfocus="setWindowElementFocus(this); window.status='Calendar'; return true;" onblur="window.status=''; return true;" onkeypress="this.className='FieldButtonLink_active'; return true;" onkeyup="this.className='FieldButtonLink_focus'; return true;" onclick="showCalendar('frmMain.inpExpectedDateTo', document.frmMain.inpExpectedDateTo.value, false);return false;">
                        <table class="FieldButton" onmouseout="this.className='FieldButton';window.status='';return true;" onmouseover="this.className='FieldButton_hover';window.status='Show calendar';return true;" onmousedown="this.className='FieldButton_active';return true;" onmouseup="this.className='FieldButton';return true;">
                          <tr>
                            <td class="FieldButton_bg">
                            </td>
                          </tr>
                        </table>
                      </a>
                    </td>
                  </tr>
                </table>
              </td>
              <td class="TitleCell"></td>
            </tr>
            <tr id="bpartnerfilterRow">
              <td class="TitleCell"><span class="LabelText">Business Partner</span></td>
              <td class="TextBox_ContentCell" colspan="2">
                <table style="border:0px;border-collapse:collapse;">
                  <tr>
                    <td style="padding-top: 0px;">
                      <script>var sc_C_BPartner_ID = null;</script>
                      <input type="hidden" name="inpcBPartnerId" id="C_BPartner_ID" value="" onreset="sc_C_BPartner_ID.resetSelector();" onchange="openbravo.Utilities.updateSmartClientComponentValue(this, sc_C_BPartner_ID.selectorField);"></input>
                      <script id="selectorLink" src="../org.openbravo.client.kernel/OBUISEL_Selector/A98899B1C75A4F4EBD3414F1B654EFAB?columnName=C_BPartner_ID&disabled=false&CssSize=TwoCells&callOut=loadGridList&DisplayLength=45.0&required=true&filterClass=org.openbravo.userinterface.selector.SelectorDataSourceFilter&_selectorDefinitionId=A98899B1C75A4F4EBD3414F1B654EFAB"></script>
                    </td>
                  </tr>
                </table>
              </td>
              <td class="TitleCell"></td>
              <td class="TitleCell"></td>
              <td class="TitleCell"></td>
            </tr>
            <tr id="glitemRow">
              <td class="TitleCell"><span class="LabelText">Received In</span></td>
              <td class="TextBox_btn_ContentCell">
                <table border="0" cellspacing="0" cellpadding="0" summary=""  style="padding-top: 0px;">
                  <tr>
                    <td class="Textbox_ContentCell">
                      <table style="border: 0px none; border-collapse: collapse;">
                        <tr><td style="padding-top: 0px;">
                        <input type="text" id="paramGLItemReceivedInAmount" class="dojoValidateValid required TextBox_btn_OneCell_width number"  value="0" maxlength="22" name="inpGLItemReceivedInAmount" onblur="numberInputEvent('onblur', this);" onfocus="numberInputEvent('onfocus', this);" onchange="" oncontextmenu="changeToEditingMode('oncontextmenu');" onpaste="changeToEditingMode('onpaste');" oncut="changeToEditingMode('oncut');" onkeypress="changeToEditingMode('onkeypress');" onkeydown="changeToEditingMode('onkeydown'); numberInputEvent('onkeydown', this, event);" onkeyup="" outputformat="euroEdition"></input>
                        </td></tr>
                      </table>
                      <span id="paramGLItemReceivedInAmountinvalidSpan" style="display: none;" class="TextBox_MsgContainer_span">
                        <table class="TextBox_MsgContainer_table">
                          <tbody><tr class="TextBox_MsgContainer_tr">
                            <td class="TextBox_MsgContainer_td"><div class="TextBox_MsgContainer_div"></div></td><td></td>
                          </tr>
                          <tr>
                            <td class="invalid" colspan="2"><div name="invalidText" id="paramGLItemReceivedInAmountinvalidSpanText" class="TextBox_MsgContainer_div2">* The value entered is not valid.</div></td>
                          </tr>
                        </tbody></table>
                      </span>
                    </td>
                    <td class="FieldButton_ContentCell">
                      <a class="FieldButtonLink" href="#" onfocus="setWindowElementFocus(this); window.status='Amount'; return true;" onblur=" window.status=''; return true;" onkeypress="this.className='FieldButtonLink_active'; return true;" onkeyup="this.className='FieldButtonLink_focus'; return true;"  onclick="calculator('frmMain.inpGLItemReceivedInAmount', document.frmMain.inpGLItemReceivedInAmount.value, false);return false;">
                        <table class="FieldButton" onmouseout="this.className='FieldButton';window.status='';return true;" onmouseover="this.className='FieldButton_hover';window.status='';return true;" onmousedown="this.className='FieldButton_active';return true;" onmouseup="this.className='FieldButton';return true;" id="NoPackageslinkCalc">
                          <tr>
                            <td class="FieldButton_bg">
                              <img alt="Calculator" class="FieldButton_Icon FieldButton_Icon_Calc" title="Amount" src="../../../../../web/images/blank.gif" border="0" id="buttonCalc"></img>
                            </td>
                          </tr>
                        </table>
                      </a>
                    </td>
                  </tr>
                </table>
              </td>
              <td class="TitleCell"></td>
              <td class="TitleCell"><span class="LabelText">Paid Out</span></td>
              <td class="TextBox_btn_ContentCell">
                <table border="0" cellspacing="0" cellpadding="0" summary=""  style="padding-top: 0px;">
                  <tr>
                    <td class="Textbox_ContentCell">
                      <table style="border: 0px none; border-collapse: collapse;">
                        <tr><td style="padding-top: 0px;">
                        <input type="text" id="paramGLItemPaidOutAmount" class="dojoValidateValid required TextBox_btn_OneCell_width number"  value="0" maxlength="22" name="inpGLItemPaidOutAmount" onblur="numberInputEvent('onblur', this);" onfocus="numberInputEvent('onfocus', this);" onchange="" oncontextmenu="changeToEditingMode('oncontextmenu');" onpaste="changeToEditingMode('onpaste');" oncut="changeToEditingMode('oncut');" onkeypress="changeToEditingMode('onkeypress');" onkeydown="changeToEditingMode('onkeydown'); numberInputEvent('onkeydown', this, event);" onkeyup="" outputformat="euroEdition"></input>
                        </td></tr>
                      </table>
                      <span id="paramGLItemPaidOutAmountinvalidSpan" style="display: none;" class="TextBox_MsgContainer_span">
                        <table class="TextBox_MsgContainer_table">
                          <tbody><tr class="TextBox_MsgContainer_tr">
                            <td class="TextBox_MsgContainer_td"><div class="TextBox_MsgContainer_div"></div></td><td></td>
                          </tr>
                          <tr>
                            <td class="invalid" colspan="2"><div name="invalidText" id="paramGLItemPaidOutAmountinvalidSpanText" class="TextBox_MsgContainer_div2">* The value entered is not valid.</div></td>
                          </tr>
                        </tbody></table>
                      </span>
                    </td>
                    <td class="FieldButton_ContentCell">
                      <a class="FieldButtonLink" href="#" onfocus="setWindowElementFocus(this); window.status='Amount'; return true;" onblur=" window.status=''; return true;" onkeypress="this.className='FieldButtonLink_active'; return true;" onkeyup="this.className='FieldButtonLink_focus'; return true;"  onclick="calculator('frmMain.inpGLItemPaidOutAmount', document.frmMain.inpGLItemPaidOutAmount.value, false);return false;">
                        <table class="FieldButton" onmouseout="this.className='FieldButton';window.status='';return true;" onmouseover="this.className='FieldButton_hover';window.status='';return true;" onmousedown="this.className='FieldButton_active';return true;" onmouseup="this.className='FieldButton';return true;" id="NoPackageslinkCalc">
                          <tr>
                            <td class="FieldButton_bg">
                              <img alt="Calculator" class="FieldButton_Icon FieldButton_Icon_Calc" title="Amount" src="../../../../../web/images/blank.gif" border="0" id="buttonCalc"></img>
                            </td>
                          </tr>
                        </table>
                      </a>
                    </td>
                  </tr>
                </table>
              </td>
              <td class="TitleCell"></td>
            </tr>
            
            <tr id="acctDimensionsTitle">
              <td colspan="6">
                <table class="FieldGroup" cellspacing="0" cellpadding="0" border="0">
                <tbody>
                  <tr class="FieldGroup_TopMargin"></tr>
                  <tr>
                    <td class="FieldGroupTitle_Left"><img class="FieldGroupTitle_Left_bg" border="0" src="../../../../../web/images/blank.gif"/></td>
                    <td class="FieldGroupTitle">Accounting Dimensions</td>
                    <td class="FieldGroupTitle_Right"><img class="FieldGroupTitle_Right_bg" border="0" src="../../../../../web/images/blank.gif"/></td>
                    <td class="FieldGroupContent"></td>
                  </tr>
                  <tr class="FieldGroup_BottomMargin"></tr>
                </tbody>
                </table>
              </td>
            </tr>
            <tr id="GLItemSection1_Dim">
              <!-- Business Partner Dimension -->
              <td id="c_bpartner_id_dim_label" class="TitleCell"><span class="LabelText">Business Partner</span></td>
              <td id="c_bpartner_id_dim_inp" class="TextBox_ContentCell" colspan="2">
                <table style="border:0px;border-collapse:collapse;">
                  <tr>
                    <td style="padding-top: 0px;">
                      <script>var sc_C_BPartner_ID_dim = null;</script>
                      <input type="hidden" name="inpCBPartnerId_dim" id="C_BPartner_ID_dim" value="" onreset="sc_C_BPartner_ID_dim.resetSelector();" onchange="openbravo.Utilities.updateSmartClientComponentValue(this, sc_C_BPartner_ID_dim.selectorField);"></input>
                      <script id="selectorLink" src="../org.openbravo.client.kernel/OBUISEL_Selector/A98899B1C75A4F4EBD3414F1B654EFAB?columnName=C_BPartner_ID_dim&disabled=false&CssSize=TwoCells&DisplayLength=45.0&required=false"></script>
                    </td>
                  </tr>
                </table>
              </td>
              <!-- Activity Dimension -->
              <td id="c_activity_id_dim_label" class="TitleCell"><span class="LabelText">Activity</span></td>
              <td id="c_activity_id_dim_inp" class="TextBox_ContentCell" colspan="1">
                <table style="border:0px;border-collapse:collapse;">
                  <tr>
                    <td style="padding-top: 0px;">
                      <script>var sc_C_Activity_ID = null;</script>
                      <input type="hidden" name="inpCActivityId" id="C_Activity_ID" value="" onreset="sc_C_Activity_ID.resetSelector();" onchange="openbravo.Utilities.updateSmartClientComponentValue(this, sc_C_Activity_ID.selectorField);"></input>
                      <script id="selectorLink" src="../org.openbravo.client.kernel/OBUISEL_Selector/FF808181312D569C01312D8C1EC40036?columnName=C_Activity_ID&disabled=false&CssSize=TwoCells&DisplayLength=45.0&required=false"></script>
                    </td>
                  </tr>
                </table>
              </td>             
              <td class="TitleCell"></td>
            </tr>
            <tr id="GLItemSection2_Dim">
              <!-- Product Dimension -->
              <td id="m_product_id_dim_label" class="TitleCell"><span class="LabelText">Product</span></td>
              <td id="m_product_id_dim_inp" class="TextBox_ContentCell" colspan="2">
                <table style="border:0px;border-collapse:collapse;">
                  <tr>
                    <td style="padding-top: 0px;">
                      <script>var sc_M_Product_ID = null;</script>
                      <input type="hidden" name="inpMProductId" id="M_Product_ID" value="" onreset="sc_M_Product_ID.resetSelector();" onchange="openbravo.Utilities.updateSmartClientComponentValue(this, sc_M_Product_ID.selectorField);"></input>
                      <script id="selectorLink" src="../org.openbravo.client.kernel/OBUISEL_Selector/FF808181312DA8D801312DDE869B000C?columnName=M_Product_ID&disabled=false&CssSize=TwoCells&DisplayLength=45.0&required=false"></script>
                    </td>
                  </tr>
                </table>
              </td>
              <!-- Campaign Dimension -->
              <td id="c_campaign_id_dim_label" class="TitleCell"><span class="LabelText">Campaign</span></td>
              <td id="c_campaign_id_dim_inp" class="TextBox_ContentCell" colspan="1">
                <table style="border:0px;border-collapse:collapse;">
                  <tr>
                    <td style="padding-top: 0px;">
                      <script>var sc_C_Campaign_ID = null;</script>
                      <input type="hidden" name="inpCampaignId" id="C_Campaign_ID" value="" onreset="sc_C_Campaign_ID.resetSelector();" onchange="openbravo.Utilities.updateSmartClientComponentValue(this, sc_C_Campaign_ID.selectorField);"></input>
                      <script id="selectorLink" src="../org.openbravo.client.kernel/OBUISEL_Selector/FF808181312D569C01312D8DCCD50045?columnName=C_Campaign_ID&disabled=false&CssSize=TwoCells&DisplayLength=45.0&required=false"></script>
                    </td>
                  </tr>
                </table>
              </td>
              <td class="TitleCell"></td>
            </tr>
            <tr id="GLItemSection3_Dim">
              <!-- Project Dimension -->
              <td id="c_project_id_dim_label" class="TitleCell"><span class="LabelText">Project</span></td>
              <td id="c_project_id_dim_inp" class="TextBox_ContentCell" colspan="2">
                <table style="border:0px;border-collapse:collapse;">
                  <tr>
                    <td style="padding-top: 0px;">
                      <script>var sc_C_Project_ID = null;</script>
                      <input type="hidden" name="inpCProjectId" id="C_Project_ID" value="" onreset="sc_C_Project_ID.resetSelector();" onchange="openbravo.Utilities.updateSmartClientComponentValue(this, sc_C_Project_ID.selectorField);"></input>
                      <script id="selectorLink" src="../org.openbravo.client.kernel/OBUISEL_Selector/FF808181312D569C01312D90408D005D?columnName=C_Project_ID&disabled=false&CssSize=TwoCells&DisplayLength=45.0&required=false"></script>
                    </td>
                  </tr>
                </table>
              </td>
              <!-- Cost center Dimension -->
              <td id="c_costcenter_id_dim_label" class="TitleCell"><span class="LabelText">Cost Center</span></td>
              <td id="c_costcenter_id_dim_inp" class="TextBox_ContentCell" colspan="1">
                <table style="border:0px;border-collapse:collapse;">
                  <tr>
                    <td style="padding-top: 0px;">
                      <script>var sc_C_Costcenter_ID = null;</script>
                      <input type="hidden" name="inpCCostcenterId" id="C_Costcenter_ID" value="" onreset="sc_C_Costcenter_ID.resetSelector();" onchange="openbravo.Utilities.updateSmartClientComponentValue(this, sc_C_Costcenter_ID.selectorField);"></input>
                      <script id="selectorLink" src="../org.openbravo.client.kernel/OBUISEL_Selector/B8321631F57E463EB617289E936BAF3A?columnName=C_Costcenter_ID&disabled=false&CssSize=TwoCells&DisplayLength=45.0&required=false"></script>
                    </td>
                  </tr>
                </table>
              </td>
              <td class="TitleCell"></td>
            </tr>
            <tr id="GLItemSection4_Dim">
              <!-- User1 Dimension -->
              <td id="user1_id_dim_label" class="TitleCell"><span class="LabelText">1st Dimension</span></td>
              <td id="user1_id_dim_inp" class="TextBox_ContentCell" colspan="2">
                <table style="border:0px;border-collapse:collapse;">
                  <tr>
                    <td style="padding-top: 0px;">
                      <script>var sc_User1_ID = null;</script>
                      <input type="hidden" name="inpUser1Id" id="User1_ID" value="" onreset="sc_User1_ID.resetSelector();" onchange="openbravo.Utilities.updateSmartClientComponentValue(this, sc_User1_ID.selectorField);"></input>
                      <script id="selectorLink" src="../org.openbravo.client.kernel/OBUISEL_Selector/814758DD755642E9BF38BD2E5AD713EC?columnName=User1_ID&disabled=false&CssSize=TwoCells&DisplayLength=45.0&required=false"></script>
                    </td>
                  </tr>
                </table>
              </td>
              <!-- User2 Dimension -->
              <td id="user2_id_dim_label" class="TitleCell"><span class="LabelText">2nd Dimension</span></td>
              <td id="user2_id_dim_inp" class="TextBox_ContentCell" colspan="1">
                <table style="border:0px;border-collapse:collapse;">
                  <tr>
                    <td style="padding-top: 0px;">
                      <script>var sc_User2_ID = null;</script>
                      <input type="hidden" name="inpUser2Id" id="User2_ID" value="" onreset="sc_User2_ID.resetSelector();" onchange="openbravo.Utilities.updateSmartClientComponentValue(this, sc_User2_ID.selectorField);"></input>
                      <script id="selectorLink" src="../org.openbravo.client.kernel/OBUISEL_Selector/BD1DA40E134A42B9889B529302A96871?columnName=User2_ID&disabled=false&CssSize=TwoCells&DisplayLength=45.0&required=false"></script>
                    </td>
                  </tr>
                </table>
              </td>
              <td class="TitleCell"></td>
            </tr>           
            <tr id="glitemAddRow">
              <td class="TitleCell"></td>
              <td class="Button_RightAlign_ContentCell">
                <div>
                  <button type="button"
                    id="buttonAddGLItem"
                    class="ButtonLink_focus"
                    onclick="addGLItem();return false;"
                    onfocus="buttonEvent('onfocus', this); window.status='OK'; return true;"
                    onblur="buttonEvent('onblur', this);"
                    onkeyup="buttonEvent('onkeyup', this);"
                    onkeydown="buttonEvent('onkeydown', this);"
                    onkeypress="buttonEvent('onkeypress', this);"
                    onmouseup="buttonEvent('onmouseup', this);"
                    onmousedown="buttonEvent('onmousedown', this);"
                    onmouseover="buttonEvent('onmouseover', this); window.status='OK'; return true;"
                    onmouseout="buttonEvent('onmouseout', this);">
                    <table class="Button">
                      <tr>
                        <td class="Button_left"><img class="Button_Icon Button_Icon_ok" alt="OK" title="OK" src="../web/images/blank.gif" id="imgButtonOK" border="0"></td>
                        <td class="Button_text Button_width" id="tdButtonOK">Add</td>
                        <td class="Button_right"></td>
                      </tr>
                    </table>
                  </button>
                </div>
              </td>
              <td class="TitleCell" colspan="4"></td>
            </tr>
            
            <tr class="FieldGroup_BottomMargin"></tr>

          </table>
        </div>
      </td>
    </tr>
    <tr>
      <td>
        <div class="Popup_ContentPane_Client" style="overflow: auto;" id="client_middle">
          <table height="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td valign="top" class="Popup_Client_Selector_DataGrid_LeftMargin">
                <table width="100%" border="0" cellspacing="0" cellpadding="0" id="tdleftSeparator">
                  <tr><td class="Popup_Client_Selector_DataGrid_LeftMargin"></td></tr>
                </table>
              </td>
              <td valign="top">
                <div id="client2" style="overflow: auto;">
                  <table cellspacing="0" cellpadding="0" width="100%" class="DataGrid_Header_Table DataGrid_Body_Table" style="table-layout: auto;" id="gridPayment">
                    <thead>
                      <tr class="DataGrid_Body_Row">
                        <th class="DataGrid_Header_LineNoCell DataGrid_Body_Cell_CheckBox" width="25"> 
                          <input type="checkbox" name="inpAllLines" onclick="markAll(document.frmMain.inpScheduledPaymentDetailId, this.checked);updateAll(true);return true;"/>
                        </th>
                        <th class="DataGrid_Header_Cell" width="120"><span name="lblP" id="lblPPON">Purchase Order No.</span><span name="lblR" id="lblRSON">Sales Order No.</span></th>
                        <th class="DataGrid_Header_Cell" width="120"><span name="lblP" id="lblPPIN">Purchase Invoice No.</span><span name="lblR" id="lblRSIN">Sales Invoice No.</span></th>
                        <th class="DataGrid_Header_Cell" width="100" id="bpGridColumn">Business Partner</th>
                        <th class="DataGrid_Header_Cell" width="100">Payment Method</th>
                        <th class="DataGrid_Header_Cell" width="70">Expected Date</th>
                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100">Invoiced Amount</th>
                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100">Expected Amount</th>
                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100">Outstanding Amount</th>
                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="110"><span name="lblP" id="lblPPayment">Payment Out</span><span name="lblR" id="lblRPayment">Payment In</span></th>
                      </tr>
                    </thead>
                    <tbody id="sectionGrid">
                    </tbody>
                  </table>
                  <table cellspacing="0" cellpadding="0" width="100%" class="DataGrid_Header_Table DataGrid_Body_Table" style="table-layout: auto;" id="gridGLItem">
                    <thead>
                      <tr class="DataGrid_Body_Row">
                        <th class="DataGrid_Header_Cell" width="300" rowspan="2">GL Item</th>
                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100" id="c_bpartner_id_th">Business Partner</th>
                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100" id="c_activity_id_th">Activity</th>
                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100" id="m_product_id_th">Product</th>
                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100" id="c_campaign_id_th">Campaign</th>
                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100" rowspan="2">Received In</th>
                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100" rowspan="2">Paid Out</th>
                        <th class="DataGrid_Header_LineNoCell" width="20" rowspan="2"></th>
                      </tr>
                      <tr class="DataGrid_Body_Row">
                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100" id="c_project_id_th">Project</th>
                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100" id="c_costcenter_id_th">Cost Center</th>
                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100" id="user1_id_th">1st Dimension</th>
                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100" id="user2_id_th">2nd Dimension</th>
                      </tr>
                    </thead>
                    <tbody id="sectionGLItemGrid">
                    </tbody>
                  </table>
                  
                  <input type="hidden" name="inpGLSumAmount" value="0" outputformat="euroEdition"/>
                  <input type="hidden" name="inpInvoiceAmount" value="0" outputformat="euroEdition"/>
                  <input type="hidden" id="inpTotal" value="0" outputformat="euroEdition"/>
                  <input type="hidden" name="inpDifference" id="inpDifference" value="0" outputformat="euroEdition"/>
                  <table cellspacing="0" cellpadding="0" width="100%" class="" style="table-layout: auto;">
                    <tr class="FieldGroup_BottomMargin"></tr>
                    <tr id="totalInvoices">
                      <td width="80%" class="LabelText" style="text-align:right">Amount on Invoices and/or Orders</td>
                      <td class="LabelText number" style="padding-right:10px;font-weight: bold;"><span id="paramInvoicesAmt"></span></td>
                    </tr>
                    <tr id="totalGLItems">
                      <td width="80%" class="LabelText" style="text-align:right">Amount on GL Items</td>
                      <td class="LabelText number" style="padding-right:10px;font-weight: bold;"><span id="paramGLItemsAmt"></span></td>
                    </tr>
                    <tr>
                      <td width="80%" class="LabelText" style="text-align:right">Total</td>
                      <td class="LabelText number" style="padding-right:10px;font-weight: bold;"><span id="paramTotal"></span></td>
                    </tr>
                    <tr id="sectionDifference">
                      <td class="LabelText" style="text-align:right">There is a difference of</td>
                      <td class="LabelText number" style="padding-right:10px;font-weight: bold;"><span id="paramDifference"></span></td>
                    </tr>
                    <tr id="sectionDifferenceBox">
                      <td></td>
                      <td>
                        <table cellspacing="0" cellpadding="0" width="100%" class="" style="border: #888888 2px solid; table-layout: auto;">
                          <tr id="underpayment">
                            <td class="Radio_Check_ContentCell" width="20">
                              <input type="radio" name="inpDifferenceAction" value="underpayment" checked="checked"/>
                            </td>
                            <td><span class="LabelText">Leave this as an underpayment</span></td>
                          </tr>
                          <tr id="credit">
                            <td class="Radio_Check_ContentCell" width="20">
                              <input type="radio" name="inpDifferenceAction" value="credit"/>
                            </td>
                            <td><span class="LabelText">Leave this amount to be used later</span></td>
                          </tr>
                          <tr id="refund">
                            <td class="Radio_Check_ContentCell" width="20">
                              <input type="radio" name="inpDifferenceAction" value="refund"/>
                            </td>
                            <td><span class="LabelText">Refund amount to customer</span></td>
                          </tr>
                          <tr id="writeoff">
                            <td class="Radio_Check_ContentCell">
                              <input type="radio" name="inpDifferenceAction" value="writeoff"/>
                            </td>
                            <td><span class="LabelText">Write off the difference</span></td>
                          </tr>
                           <tr id="writeofflimit">
                            <td class="Radio_Check_ContentCell" >
                              <input type="radio" name="inpDifferenceAction" value="writeofflimit" id="radiolimit" DISABLED/>
                            </td>
                            <td><span class="LabelText">Write off the difference (Above limit)</span></td>
                          </tr>       
                        </table>
                      </td>
                    </tr>
                  </table>
                </div>
              </td>
              <td valign="top" class="Popup_Client_Selector_DataGrid_RightMargin">
                <table width="100%" border="0" cellspacing="0" cellpadding="0" id="tdrightSeparator">
                  <tr><td class="Popup_Client_Selector_DataGrid_RightMargin"></td></tr>
                </table>
              </td>
            </tr>
            
          </table>
        </div>
      </td>
    </tr>
    
    <tr>
      <td>
        <div class="Popup_ContentPane_Client" style="overflow: auto; padding-bottom: 5px;" id="client_bottom">
          <table cellspacing="0" cellpadding="0" class="Popup_Client_TableSelector">

            <tr>
              <td class="TableEdition_OneCell_width"></td>
              <td class="TableEdition_OneCell_width"></td>
              <td class="TableEdition_OneCell_width"></td>
              <td class="TableEdition_OneCell_width"></td>
              <td class="TableEdition_OneCell_width"></td>
              <td class="TableEdition_OneCell_width"></td>
            </tr>
            <tr>
              <td></td>
              <td></td>
              <td class="Button_RightAlign_ContentCell">
                <div>
                  <button type="button" 
                    id="buttonProcess"
                    class="ButtonLink" 
                    onclick="bPartnerBlocked(this);return false;"
                    onfocus="buttonEvent('onfocus', this); window.status='Create'; return true;"
                    onblur="buttonEvent('onblur', this);"
                    onkeyup="buttonEvent('onkeyup', this);"
                    onkeydown="buttonEvent('onkeydown', this);"
                    onkeypress="buttonEvent('onkeypress', this);"
                    onmouseup="buttonEvent('onmouseup', this);"
                    onmousedown="buttonEvent('onmousedown', this);"
                    onmouseover="buttonEvent('onmouseover', this); window.status='Create'; return true;"
                    onmouseout="buttonEvent('onmouseout', this);">
                    <table class="Button">
                      <tr>
                        <td class="Button_left"><img class="Button_Icon Button_Icon_ok" alt="Process" title="Process" src="../../../../../web/images/blank.gif" border="0" /></td>
                        <td class="Button_text Button_width">Process</td>
                        <td class="Button_right"></td>
                      </tr>
                    </table>
                  </button>
                </div>
              </td>
              <td class="Button_LeftAlign_ContentCell">
                <div>
                  <button type="button" 
                    id="buttonCancel" 
                    class="ButtonLink" 
                    onclick="closePage();return false;"
                    onfocus="buttonEvent('onfocus', this); window.status='Cancel'; return true;"
                    onblur="buttonEvent('onblur', this);"
                    onkeyup="buttonEvent('onkeyup', this);"
                    onkeydown="buttonEvent('onkeydown', this);"
                    onkeypress="buttonEvent('onkeypress', this);"
                    onmouseup="buttonEvent('onmouseup', this);"
                    onmousedown="buttonEvent('onmousedown', this);"
                    onmouseover="buttonEvent('onmouseover', this); window.status='Cancel'; return true;"
                    onmouseout="buttonEvent('onmouseout', this);">
                    <table class="Button">
                      <tr>
                        <td class="Button_left"><img class="Button_Icon Button_Icon_cancel" alt="Cancel" title="Cancel" src="../../../../../web/images/blank.gif" border="0" /></td>
                        <td class="Button_text Button_width">Cancel</td>
                        <td class="Button_right"></td>
                      </tr>
                    </table>
                  </button>
                </div>
              </td>
              <td></td>
              <td></td>
            </tr>
          </table>
        </div>
      </td>
    </tr>
  </table>
</form>
</body>
</html>
